package com.arox.springinaction.security;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class MessageBoardServiceImpl implements MessageBoardService {
    
    private long currentId = 1;
    private Map<Long, Message> messages = new LinkedHashMap<Long, Message>();

    public List<Message> listMessages() {
	return new ArrayList<Message>(messages.values());
    }

    public synchronized void postMessage(Message message) {
	message.setId(currentId++);
	messages.put(message.getId(), message);
    }

    public synchronized void deleteMessage(Message message) {
	messages.remove(message.getId());
    }

    public Message findByMessageId(Long messageId) {
	return messages.get(messageId);
    }

}
